package servlets;

import beans.System_Beans;
import beans.Unit_Beans;
import beans.Unit_Logic_Beans;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

@WebServlet(name = "unit",urlPatterns = "/unit")
public class Unit_Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String UNITACCNAME, UNITADDR,ORGCODE,UNITCHAR,
                UNITKIND,SALARYDATE,NUITPHOME,UNITLINKMAN,
                UNITAGENTPAPNO,UNITPROP,PERPROP,REMARK;

        UNITACCNAME = req.getParameter("UNITACCNAME");
        UNITADDR = req.getParameter("UNITADDR");
        ORGCODE = req.getParameter("ORGCODE");
        UNITCHAR = req.getParameter("UNITCHAR");
        UNITKIND = req.getParameter("UNITKIND");
        SALARYDATE = req.getParameter("SALARYDATE");
        NUITPHOME = req.getParameter("NUITPHOME");
        UNITLINKMAN = req.getParameter("UNITLINKMAN");
        UNITAGENTPAPNO = req.getParameter("UNITAGENTPAPNO");
        UNITPROP = req.getParameter("UNITPROP");
        PERPROP = req.getParameter("PERPROP");
        REMARK = req.getParameter("REMARK");


        //数据 bean
        Unit_Beans unit_beans = new Unit_Beans();
        unit_beans.setUNITACCNUM(UNITACCNAME);
        unit_beans.setUNITADDR(UNITADDR);
        unit_beans.setORGCODE(ORGCODE);
        unit_beans.setUNITCHAR(UNITCHAR);
        unit_beans.setUNITKIND(UNITKIND);
        unit_beans.setSALARYDATE(SALARYDATE);
        unit_beans.setNUITPHOME(NUITPHOME);
        unit_beans.setUNITLINKMAN(UNITLINKMAN);
        unit_beans.setUNITAGENTPAPNO(UNITAGENTPAPNO);
        unit_beans.setUNITPROP(Double.parseDouble(UNITPROP));
        unit_beans.setPERPROP(Double.parseDouble(PERPROP));

        //逻辑 bean
        Unit_Logic_Beans unit_logic_beans = new Unit_Logic_Beans();
        List<Unit_Beans> list = unit_logic_beans.Select_Unit(unit_beans);

        if (!(list.isEmpty())){
            int n=unit_logic_beans.Insert_Unit(unit_beans);
            if (n>0){
                System.out.println("ok!");
            }
        }
    }
}
